home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Tool Chest / Development Tools & Languages / HyperCard Related / APDA HyperCard Toolkits / HyperCard Video Toolkit 2.0 / HVT #2 / Advanced Material / Video Sources / vidDrvrP4200.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  13.7 KB  |  473 lines  |  [TEXT/MPS ]

  1. (*
  2.     vidDrvrP4200(cmd,parameters) -- Driver for the Pioneer 4200 videodisc player. The cmd parameter specifies the
  3.         function to be performed (p1 is the first parameter after cmd; p2 is the second, etc.):
  4.  
  5.                     Command        Function
  6.                     ---------        --------
  7.                     chapter            Return the chapter currently being displayed.
  8.                     control            Execute a series of control functions. Each addition parameter is a keyword to be
  9.                                         executed. If the keyword doesn't make sense here, pass it on to configureSPort.
  10.                                         The following keywords are understood by the video driver:
  11.                                                     Keyword                        Function
  12.                                                     --------                        --------
  13.                                                     init or reset                    Reset the player, configure the serial port (the baud rate is set to
  14.                                                                                         the highest available for the selected player).
  15.                                                     eject or reject                Eject the disc from the player.
  16.                                                     audioOff                        Turn off both audio channels.
  17.                                                     audio1On                        Turn on audio channel 1.
  18.                                                     audio2On                        Turn on audio channel 2.
  19.                                                     stereoOn                        Turn on both audio channels.
  20.                                                     pictureOn/pictureOff    Turn on/off the picture.
  21.                                                     framesOn/framesOff    Turn on/off the display of frame numbers.
  22.                                                     frameMode                    Set player to frame number mode.
  23.                                                     chapterMode                    Set player to chapter number mode.
  24.                                                     timeMode                        Set player to time mode.
  25.                                                     defaultComm                    Set default communications settings for this player.
  26.                     extended        Execute a function specific to the player. This player doesn't have any (yet).
  27.                     fps                Set the frames per second for the next playVideo command to p1, which can be a number or
  28.                                         one of "slowest", "slower", "slow", "normal", "fast", "faster", "fastest".
  29.                     frame            Return the current frame number.
  30.                     name            Return the long name of the player.
  31.                     play                Start a sequence playing, from p1 to p2, which are frame numbers, chapter numbers, or times,
  32.                                         depending upon the mode.
  33.                     scan                Scan forward or backward, depending upong whether p1 is "forward" or "backward".
  34.                     search            Search to frame, chapter, or time p1.
  35.                     sendCmd        Send command p1 to the player and wait for an acknowlege.
  36.                     speeds            Return the frames per second speeds allowed with this player.
  37.                     status            Return the status of the play, which is a comma-separated list containing:
  38.                                                         Keyword                                            Meaning
  39.                                                         --------                                            --------
  40.                                                         doorOpen or park or still or play        State of player.
  41.                                                         CLV or CAV                                        Type of disc.
  42.                                                         disc12inch or disc8inch                        Size of disc being played.
  43.                                                         side1 or side2                                    Side of disc being played.
  44.                     step                Step p1 frames forward (or backward if it's negative), and do it p2 times.
  45.                     time                Return the time of the frame currently being displayed, in 1/60ths of a second since the start
  46.                                         of the disc.
  47.                     version            Return the version of this player driver.
  48.  
  49.     To compile and link this file using Macintosh Programmer's Workshop,
  50.  
  51.         pascal -w vidDrvrP4200.p
  52.         link -m ENTRYPOINT -o HyperCommands -rt XFCN=8030 -sn Main=vidDrvrP4200 ∂
  53.             vidDrvrP4200.p.o "{MPW}"Libraries:interface.o "{MPW}"PLibraries:PasLib.o
  54.  
  55.     Copyright © 1988 Apple Computer, Inc.
  56.  
  57.     2/88 - Initial coding by Harry R. Chesley.
  58. *)
  59.  
  60. {$R-}
  61.  
  62. {$S vidDrvrP4200 }     { Segment name must be the same as the command name. }
  63.  
  64. unit DummyUnit;
  65.  
  66. interface
  67.  
  68. uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
  69.  
  70. procedure EntryPoint(paramPtr: XCmdPtr);
  71.     
  72. implementation
  73.  
  74. type
  75.  
  76. Str31 = String[31];
  77.  
  78. procedure vidDrvrP4200(paramPtr: XCmdPtr); forward;
  79.  
  80. procedure EntryPoint(paramPtr: XCmdPtr);
  81.  
  82.     begin
  83.         vidDrvrP4200(paramPtr);
  84.     end;
  85.  
  86. procedure vidDrvrP4200(paramPtr: XCmdPtr);
  87.  
  88.     var returnValue: str255;
  89.         pCount: integer;
  90.         p1, p2: str255;
  91.         str: str255;
  92.         i: integer;
  93.  
  94.     {$I XCmdGlue.inc}
  95.  
  96.     procedure Fail(errMsg: Str255); { set theResult and quit }
  97.         begin
  98.             paramPtr^.returnValue := PasToZero(errMsg);
  99.             exit(vidDrvrP4200);
  100.         end;
  101.  
  102.     {$I VideoUtil.inc}
  103.  
  104.     procedure sendCmd(theCommand: str255);
  105.         { Send a command to the player and wait for the ack. }
  106.  
  107.         begin
  108.             SendCardMessage(Concat('sendSPort "',theCommand,'" & return'));
  109.             EvalAndDispose('RecvUpTo("R",600,empty)');
  110.         end;
  111.  
  112.     function chapter: str255;
  113.         { Get the current chapter number from the player. }
  114.  
  115.         var theResult: str255;
  116.  
  117.         begin
  118.             { Get the current chapter number... }
  119.             SendCardMessage('sendSPort "?C" & return');
  120.             theResult := EvalStr('recvUpTo(return,30,empty)');
  121.             if length(theResult) <= 1 then chapter := 'noAnswer'
  122.             else chapter := Copy(theResult,1,length(theResult)-1);
  123.         end;
  124.  
  125.     procedure search(var toFrame: str255; blankSearch: boolean);
  126.         { Search to a particular frame number, blanking if indicated. }
  127.  
  128.         begin
  129.             if blankSearch then SendCmd('0 VD');
  130.             SendCmd(Concat(toFrame,' SE'));
  131.             if blankSearch then SendCmd('1 VD');
  132.         end;
  133.  
  134.     procedure stop;
  135.         { Stop the player. }
  136.  
  137.         begin
  138.             SendCmd('ST');
  139.         end;
  140.  
  141.     procedure control(var keywd: str255);
  142.         { Handle a control command. }
  143.  
  144.         type
  145.             audioModes = (off,oneOn,twoOn,stereo);
  146.  
  147.         var numberOfParms: integer;
  148.             i: integer;
  149.             parm: str255;
  150.  
  151.         procedure ejectPlayer;
  152.             { Eject the disc. }
  153.     
  154.             begin
  155.                 { Send the appropriate eject command. }
  156.                 SendCmd('RJ OP');
  157.             end;
  158.     
  159.         procedure audio(onOff: audioModes);
  160.             { Set the audio mode. }
  161.     
  162.             begin
  163.                 { Send the appropriate audio channel command. }
  164.                 case onOff of
  165.                     off: SendCmd('0 AD');
  166.                     oneOn: SendCmd('1 AD');
  167.                     twoOn: SendCmd('2 AD');
  168.                     stereo: SendCmd('3 AD');
  169.                     end;
  170.             end;
  171.     
  172.         procedure picture(onOff: boolean);
  173.             { Turn the picture on or off. }
  174.     
  175.             begin
  176.                 { Send the appropriate picture command. }
  177.                 if onOff then SendCmd('1 VD')
  178.                 else SendCmd('0 VD');
  179.             end;
  180.     
  181.         procedure frames(onOff: boolean);
  182.             { Turn the frame number display on or off. }
  183.     
  184.             begin
  185.                 { Send the appropriate frame display command. }
  186.                 if onOff then SendCmd('1 DS 3 RA')
  187.                 else SendCmd('0 DS');
  188.             end;
  189.     
  190.         procedure defaultComm;
  191.             { Set the default communications configuration. }
  192.  
  193.             begin
  194.                 { Set the port configuration. }
  195.                 SendCardMessage('configureSPort baud4800,echoOff,editOff,linefeedOff,stripOff');
  196.             end;
  197.  
  198.         procedure setMode(theMode: str255);
  199.             { Set the frame/chapter/time mode. }
  200.     
  201.             begin
  202.                 SetStrGlobal('videoMode',theMode);
  203.                 if StringEqual(theMode,'chapterMode') then sendCmd('CH')
  204.                 else if StringEqual(theMode,'timeMode') then sendCmd('TM')
  205.                 else sendCmd('FR');
  206.             end;
  207.     
  208.         procedure initPlayer;
  209.             { Initialize the player. }
  210.     
  211.             begin
  212.                 { Empty out the globals. }
  213.                 SetStrGlobal('videoMode','');
  214.                 SetStrGlobal('blankNextVideo','');
  215.                 SetStrGlobal('videoSpeed','');
  216.     
  217.                 { Send the reset command for this player. }
  218.                 SendCardMessage('sendSPort "SA" & return');
  219.                 { Wait for the ack. }
  220.                 EvalAndDispose('recvUpTo("R",1200,empty)');
  221.  
  222.                 { Force it to stop. }
  223.                 stop;
  224.  
  225.                 { Reset the player to known defaults. }
  226.                 setMode('');
  227.                 audio(stereo);
  228.                 frames(false);
  229.                 picture(true);
  230.             end;
  231.     
  232.         begin
  233.             if StringEqual(keywd,'init') or StringEqual(keywd,'reset') then initPlayer
  234.             else if StringEqual(keywd,'eject') or StringEqual(keywd,'reject') then ejectPlayer
  235.             else if StringEqual(keywd,'audioOff') then audio(off)
  236.             else if StringEqual(keywd,'audio1On') then audio(oneOn)
  237.             else if StringEqual(keywd,'audio2On') then audio(twoOn)
  238.             else if StringEqual(keywd,'stereoOn') then audio(stereo)
  239.             else if StringEqual(keywd,'pictureOn') then picture(true)
  240.             else if StringEqual(keywd,'pictureOff') then picture(false)
  241.             else if StringEqual(keywd,'framesOn') then frames(true)
  242.             else if StringEqual(keywd,'framesOff') then frames(false)
  243.             else if StringEqual(keywd,'defaultComm') then defaultComm
  244.             else if StringEqual(keywd,'frameMode') then setMode('')
  245.             else if StringEqual(keywd,'chapterMode') then setMode('chapterMode')
  246.             else if StringEqual(keywd,'timeMode') then setMode('timeMode')
  247.             else SendCardMessage(Concat('configureSPort ',keywd));
  248.         end;
  249.  
  250.     function extended(var keywd: str255): str255;
  251.         { Perform an extended command or function. }
  252.  
  253.         begin
  254.             { No extended commands for this player. }
  255.         end;
  256.  
  257.     procedure fps(var fpsKeywd: str255);
  258.         { Set the frames per second. }
  259.  
  260.         begin
  261.             { Default speed settings are fine. }
  262.         end;
  263.  
  264.     function frame: str255;
  265.         { Return the current frame number. }
  266.  
  267.         var str: str255;
  268.  
  269.         begin
  270.             { Get the current frame number... }
  271.             SendCardMessage('sendSPort "?F" & return');
  272.             str := EvalStr('recvUpTo(return,30,empty)');
  273.             if length(str) <= 1 then frame := 'noAnswer'
  274.             else frame := Copy(str,1,length(str)-1);
  275.         end;
  276.  
  277.     function name: str255;
  278.         { Return the long name of the player. }
  279.  
  280.         begin
  281.             name := 'Pioneer 4200';
  282.         end;
  283.  
  284.     procedure play(var firstFrame,lastFrame,speed: str255; blankSearch: boolean);
  285.         { Play a segment. }
  286.  
  287.         var lastFrameNum: longInt;
  288.             startHere: boolean;
  289.             playToLast: boolean;
  290.             rev: boolean;
  291.  
  292.         begin
  293.             { Figure out if we're playing to special (non-numeric markers). }
  294.             startHere := StringEqual(firstFrame,'here');
  295.             playToLast := StringEqual(lastFrame,'lastFrame');
  296.             if playToLast then
  297.                 begin
  298.                     lastFrame := '54000';
  299.                     lastFrameNum := 54000;
  300.                 end
  301.             else lastFrameNum := StrToLong(lastFrame);
  302.  
  303.             { Figure out whether we're playing forward or reverse. }
  304.             rev := (not playToLast) and
  305.                         (((not startHere) and (lastFrameNum < StrToLong(firstFrame))) or (lastFrameNum = 0));
  306.  
  307.             { Search to the first frame. }
  308.             if not startHere then search(firstFrame,blankSearch);
  309.             { Set the speed. }
  310.             SendCmd(Concat(LongToStr(2*StrToLong(speed)),' SP'));
  311.             { Set the stopping point. }
  312.             if (not playToLast) and (lastFrameNum <> 0) then SendCmd(Concat(lastFrame,' SM'));
  313.             { Play it. }
  314.             if rev then SendCmd('MR')
  315.             else
  316.                 begin
  317.                     if StringEqual(speed,'30') then SendCmd('PL')
  318.                     else SendCmd('MF');
  319.                 end;
  320.         end;
  321.  
  322.     function scan(scanForward: boolean): str255;
  323.         { Scan forward (if scanForward is true) or backward. }
  324.  
  325.         begin
  326.             if scanForward then SendCmd('NF')
  327.             else SendCmd('NR');
  328.             scan := '';
  329.         end;
  330.  
  331.     procedure step(goForward: boolean);
  332.         { Step one frame forward (if goForward is true) or backward. }
  333.  
  334.         begin
  335.             if goForward then SendCmd('SF')
  336.             else SendCmd('SR');
  337.         end;
  338.  
  339.     function speeds: str255;
  340.         { Return the valid speed for this player. }
  341.  
  342.         begin
  343.             speeds := '1,2,3,4,5,6,7,8,9,10,15,20,30,60,90,120';
  344.         end;
  345.  
  346.     function status: str255;
  347.         { Return the current status of the player. }
  348.  
  349.         var statusString: str255;
  350.             theResult: str255;
  351.  
  352.         begin
  353.             SendCardMessage('sendSPort "?P" & return');
  354.             statusString := EvalStr('recvUpTo(return,30,empty)');
  355.             theResult := 'noAnswer';
  356.             if length(statusString) >= 3 then
  357.                 if statusString[1] = 'P' then
  358.                     begin
  359.                         case statusString[3] of
  360.                             '0','1': theResult := 'park';
  361.                             '4', '9': theResult := 'play';
  362.                             '5','6': theResult := 'still';
  363.                             otherwise theResult := '';
  364.                             end;
  365.                         EvalAndDispose('recvUpTo(empty,10,empty)');
  366.                         SendCardMessage('sendSPort "?D" & return');
  367.                         statusString := EvalStr('recvUpTo(return,30,empty)');
  368.                         if length(statusString) >= 4 then
  369.                             begin
  370.                                 theResult := Concat(theResult,',');
  371.                                 case statusString[2] of
  372.                                     '0': theResult := Concat(theResult,'CAV');
  373.                                     '1': theResult := Concat(theResult,'CLV');
  374.                                     end;
  375.                                 theResult := Concat(theResult,',');
  376.                                 case statusString[3] of
  377.                                     '0': theResult := Concat(theResult,'disc12inch');
  378.                                     '1': theResult := Concat(theResult,'disc8inch');
  379.                                     end;
  380.                                 theResult := Concat(theResult,',');
  381.                                 case statusString[4] of
  382.                                     '0': theResult := Concat(theResult,'side1');
  383.                                     '1': theResult := Concat(theResult,'side2');
  384.                                     end;
  385.                             end;
  386.                     end;
  387.             status := theResult
  388.         end;
  389.  
  390.     function time: str255;
  391.         { Return the time for the current frame. }
  392.  
  393.         var theResult: str255;
  394.  
  395.         begin
  396.             { Get the current frame time... }
  397.             SendCardMessage('sendSPort "?T" & return');
  398.             theResult := EvalStr('recvUpTo(return,30,empty)');
  399.             time := EvalStr(Concat('HMSToTicks(',Copy(str,1,length(theResult)-1),'00'));
  400.         end;
  401.  
  402.     function version: str255;
  403.         { Return the version of this driver. }
  404.  
  405.         begin
  406.             version := 'P4200 1.0';
  407.         end;
  408.  
  409.     begin
  410.         pCount := paramPtr^.paramCount;
  411.  
  412.         if pCount <= 0 then Fail('parameter count is not > 0');
  413.  
  414.         if pCount > 1 then GetStrParm(2,p1)
  415.         else p1 := '';
  416.         if pCount > 2 then GetStrParm(3,p2)
  417.         else p2 := '';
  418.  
  419.         GetStrParm(1,str);
  420.  
  421.         returnValue := '';
  422.  
  423.         if StringEqual(str,'chapter') then returnValue := chapter
  424.         else if StringEqual(str,'control') then
  425.             begin
  426.                 for i := 2 to pCount do
  427.                     begin
  428.                         GetStrParm(i,str);
  429.                         control(str);
  430.                     end;
  431.             end
  432.         else if StringEqual(str,'extended') then returnValue := extended(p1)
  433.         else if StringEqual(str,'fps') then fps(p1)
  434.         else if StringEqual(str,'frame') then returnValue := frame
  435.         else if StringEqual(str,'name') then returnValue := name
  436.         else if StringEqual(str,'play') then
  437.             begin
  438.                 GetStrGlobal('blankNextVideo',str);
  439.                 if str = '' then
  440.                     begin
  441.                         GetStrGlobal('videoSpeed',str);
  442.                         play(p1,p2,str,false);
  443.                     end
  444.                 else
  445.                     begin
  446.                         GetStrGlobal('videoSpeed',str);
  447.                         play(p1,p2,str,true);
  448.                     end;
  449.             end
  450.         else if StringEqual(str,'scan') then
  451.             begin
  452.                 if length(p1) < 1 then returnValue := scan(true)
  453.                 else returnValue := scan(not ((p1[1] = 'b') or (p1[1] = 'B')));
  454.             end
  455.         else if StringEqual(str,'search') then
  456.             begin
  457.                 GetStrGlobal('blankNextVideo',str);
  458.                 search(p1,str <> '');
  459.             end
  460.         else if StringEqual(str,'sendCmd') then sendCmd(p1)
  461.         else if StringEqual(str,'step') then step(p1 = '1')
  462.         else if StringEqual(str,'speeds') then returnValue := speeds
  463.         else if StringEqual(str,'status') then returnValue := status
  464.         else if StringEqual(str,'stop') then stop
  465.         else if StringEqual(str,'time') then returnValue := time
  466.         else if StringEqual(str,'version') then returnValue := version;
  467.  
  468.         { Return the result (if any). }
  469.         paramPtr^.returnValue := PasToZero(returnValue)
  470.     end;
  471.  
  472. end.
  473.